package com.yanqu.road.server.cmd.activity.sonhai;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.sonhai.data.SonHaiEggData;
import com.yanqu.road.entity.player.CrossUserBaseInfo;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SonHaiProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivity;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivityMgr;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiUser;
import com.yanqu.road.server.manager.activity.sonhai.pb.SonHaiActivityPb;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C2_SON_HAI_AFTER_LOGIN_HANDLE, desc = "山海伏兽-登录后处理")
public class CrossSonHaiAfterLoginHandleCmd extends CrossUnionCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        SonHaiProto.SonHaiCrossAfterLoginHandleReqMsg reqMsg = SonHaiProto.SonHaiCrossAfterLoginHandleReqMsg.parseFrom(packet.getBytes());
        CrossSonHaiActivity activity = CrossSonHaiActivityMgr.getActivity(reqMsg.getActivityId(), groupId);
        if (activity == null) {
            return;
        }
        //热更处理一下，活动结束后不执行以下方法
        try {
            ActivityInfo activityInfo = ActivityMgr.getActivityInfo(reqMsg.getActivityId());
            if (activityInfo == null) {
                return;
            }
            if (!ActivityHelper.activityInShowTime(activityInfo)) {
                return;
            }
        } catch (Exception e) {
            log.error("CrossSonHaiAfterLoginHandleCmd error", e);
            return;
        }
        //队伍积分同步
        activity.syncTeamScoreUpdate(packet.getPlayerId());
        //同步玩家数据
        activity.syncUserData(packet.getPlayerId(), false);
        //同步红点
        activity.syncUserAllRedDot(packet.getPlayerId());
    }

    @Override
    public void sendData() {

    }
}
